package com.test.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {
	private String driverClassName = "com.mysql.cj.jdbc.Driver"; 
	  private String url = "jdbc:mysql://localhost:3306/stest?useUnicode=true&characterEncoding=utf-8"; 
	  private String userName = "root"; 
	  private String password = "123456"; 
	  /* 
	  private static ConnectionFactory connectionFactory=null; 
	  
	  
	  private ConnectionFactory() { 
		  try {
			Class.forName(driverClassName);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	  }
	  public ConnectionFactory(){
		  
	  }
	 */
	  public Connection getConnection() throws SQLException 
	  { 
		  try {
				Class.forName(driverClassName);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				System.out.println("驱动异常");
			} 
		  return DriverManager.getConnection(url, userName, password); 
	  }
	  /*
	  public static ConnectionFactory getInstance() 
	  {  
		  if (null==connectionFactory) { 
		      connectionFactory=new ConnectionFactory(); 
		    } 
		    return connectionFactory;
	  }
	  */
	  

}

